#!/usr/bin/python3
import testbase
testbase.login()
testbase.deleteByID('tmodel','ALL')
testbase.deleteByID('catalog','ALL')
testbase.deleteByID('business','ALL')


testbase.update('business',{"u_id":"common","s_name":"通用"})
testbase.update('catalog',{"u_id":"root","s_name":"通用","business_id":"common"})
testbase.update('catalog',{"u_id":"c1","s_name":"test","business_id":"common","parent_id":"root"})
body = {
    "identifier" : "mtest",
    "published" : "true",
    "name":"mtest",
    "properties":[
        {
            "identifier" : "p1",
            "name":"p1",
            "published" : "true",
            "access_mode" : "rw",
            "data_type": {
                "type":"int",
                "min":"-100",
                "max":"100",
                "unit":"C",
                "unit_name":"temperature",
            } 

        },
        {
            "identifier" : "p2",
            "name":"p2",
            "published" : "true",
            "access_mode" : "rw",
            "data_type": {
                "type":"enum",
                "unit":"C",
                "unit_name":"temperature",
                "value_list":
                [
                    {
                        "value":1,
                        "desc":"too high"
                    },
                    {
                        "value":2,
                        "desc":"too high2"
                    }
                ]
                
            } 

        },
        {
            "identifier" : "p3",
            "name":"p3",
            "published" : "false",
            "access_mode" : "rw",
            "data_type": {
                "type":"array",
                "item":
                {
                    "type":"struct",
                    "data_type":{
                        "struct_specs":[
                            {
                                "identifier" : "sp1",
                                "name":"sp1",
                                "data_type":{
                                    "type":"int",
                                    "min":"-100",
                                    "max":"100",
                                    "unit":"C",
                                    "unit_name":"temperature",
                                }
                            },
                            {
                                "identifier" : "sp2",
                                "name":"sp2",
                                "data_type":{
                                    "type":"int",
                                    "min":"-100",
                                    "max":"100",
                                    "unit":"C2",
                                    "unit_name":"temperature",
                                }
                            }
                        ]
                    }
                }
            } 

        },
    ]
}

m = {"u_id":"mtest","s_name":"mtest","catalog_id":"c1"}
m['body'] = body
testbase.update('tmodel',m)
m2 = {"u_id":"2","s_name":"2","catalog_id":"c1"}
m2['body'] = {
    "identifier" : "2",
    "name":"2",
    "properties":
    [
        {
            "identifier" : "p1",
            "name":"p1",
            "access_mode" : "rw",
            "data_type": 
            {
                "type":"int",
                "min":"-100",
                "max":"100",
                "unit":"C",
                "unit_name":"temperature",
            } 

        }
    ]
}

testbase.update('tmodel',m2)
testbase.getByID("tmodel","query?isPublished=true")
testbase.getByID("tmodel","mtest")
#testbase.deleteByID('tmodel','ALL')
#testbase.deleteByID('catalog','ALL')
#testbase.deleteByID('business','ALL')